#include "widget.h"
#include "ui_widget.h"
#include <QMouseEvent>
#include<QGraphicsDropShadowEffect>
#include<QList>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    initUI();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::initUI()
{
    setWindowFlag(Qt::WindowType::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    QGraphicsDropShadowEffect* shadowEffect = new QGraphicsDropShadowEffect(this);
    shadowEffect->setOffset(0,0);
    shadowEffect->setColor("#000000");
    shadowEffect->setBlurRadius(10);
    this->setGraphicsEffect(shadowEffect);
    ui->Rec->seticon(":/QTmap/map/rec.png", "推荐", 1);
    ui->music->seticon(":/QTmap/map/musichall", "音乐馆", 2);
    ui->audio->seticon(":/QTmap/map/diantai.png", "电台", 3);
    ui->like->seticon(":/QTmap/map/like.png", "我喜欢", 4);
    ui->local->seticon(":/QTmap/map/local.png", "本地下载", 5);
    ui->recent->seticon(":/QTmap/map/recentplay.png", "最近播放", 6);
}


void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt:: LeftButton)
    {
        dragPosition = event->globalPos() - frameGeometry().topLeft();
        return;
    }
    QWidget::mousePressEvent(event);
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons() == Qt::LeftButton)
    {
        move(event->globalPos() - dragPosition);
        return;
    }
    QWidget::mouseMoveEvent(event);
}

void Widget::onBuFromClick(int id)
{
    QList<btForm*> buttonList = this->findChildren<btForm*>();
    foreach(btForm* btitem, buttonList)
    {
        if (id != btitem->getId())
        {
            btitem->clearBg();
        }
    }
    ui->stackedWidget->setCurrentIndex(id - 1);
}

void Widget::connectSignalAndSlot()
{
    // ⾃定义的btFrom按钮点击信号，当btForm点击后，设置对应的堆叠窗⼝
     connect(ui->rec, &btFrom::click, this, &QQMusic::onBtFormClick);
     connect(ui->musics, &btFrom::click, this, &QQMusic::onBtFormClick);
     connect(ui->audio, &btFrom::click, this, &QQMusic::onBtFormClick);
     connect(ui->like, &btFrom::click, this, &QQMusic::onBtFormClick);
     connect(ui->local, &btFrom::click, this, &QQMusic::onBtFormClick);
     connect(ui->recent, &btFrom::click, this, &QQMusic::onBtFormClick);sd
}

